package com.zryc.shop.pms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.pms.entity.Product;
import com.zryc.shop.pms.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@Api(tags = "商品管理接口列表")
@RequestMapping("/pms/product")
public class ProductController {

    @Autowired
    private IProductService productService;
    @PostMapping("/create")
    @ApiOperation("新增商品")
    public Result create(@RequestBody Product product) {
        return Result.ok(productService.create(product));
    }

    @GetMapping("/simpleList")
    @ApiOperation("查询商品简略信息列表")
    public Result simpleList(@RequestParam @ApiParam(value = "商品名称/货号关键词") String keyword){
        return Result.ok(productService.simpleList(keyword));
    }

    @PostMapping("/update/publishStatus")
    @ApiOperation("更新上架商品状态")
    public Result updatePublishStatus(@RequestParam String ids, @RequestParam Integer publishStatus) {
        return Result.ok(productService.updatePublishStatus(ids, publishStatus));
    }

    @PostMapping("/update/newStatus")
    @ApiOperation("更新商品是否新品状态")
    public Result updateNewStatus(@RequestParam String ids, @RequestParam Integer newStatus) {
        return Result.ok(productService.updateNewStatus(ids, newStatus));
    }

    @PostMapping("/update/recommendStatus")
    @ApiOperation("更新商品是否推荐状态")
    public Result updateRecommendStatus(@RequestParam  String ids, @RequestParam Integer recommendStatus) {
        return Result.ok(productService.updateRecommendStatus(ids, recommendStatus));
    }
    @GetMapping("/updateInfo/{id}")
    @ApiOperation("获取当前商品信息")
    public Result updateInfo(@PathVariable @ApiParam(value = "商品id", required = true) Long id) {
        return Result.ok(productService.selectProductById(id));
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("获取当前商品信息")
    public Product detail(@PathVariable @ApiParam(value = "商品id", required = true) Long id) {
        return productService.getById(id);
    }

    @PostMapping("/update/{id}")
    @ApiOperation("更新当前商品信息")
    public Result update(@PathVariable @ApiParam(value = "商品id", required = true) Long id,@RequestBody Product product) {
        return Result.ok(productService.updateProduct(id,product));
    }

    @GetMapping("/list")
    @ApiOperation("分页查询商品列表")
    public Result list(@RequestParam(required = false) @ApiParam(value = "商品名") String keyword,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "5") @ApiParam(value = "每页大小", required = true) Integer pageSize,
                       @RequestParam(required = false) @ApiParam(value = "上架状态") Integer publishStatus,
                       @RequestParam(required = false) @ApiParam(value = "审核状态") Integer verifyStatus,
                       @RequestParam(required = false) @ApiParam(value = "商品货号") String productSn,
                       @RequestParam(required = false) @ApiParam(value = "商品品牌") Long brandId,
                       @RequestParam(required = false) @ApiParam(value = "商品分类") Long productCategoryId
    ) throws InterruptedException {
        return Result.ok(productService.list(keyword, pageNum, pageSize, publishStatus, verifyStatus, productSn, brandId, productCategoryId));
    }

    @PostMapping("/update/deleteStatus")
    @ApiOperation("修改删除状态")
    public Result delete(String ids, Integer deleteStatus){
        return Result.ok(productService.updateDeleteStatus(ids,deleteStatus));
    }

    @GetMapping("/{id}/{count}")
    public Result recieve(@PathVariable("id") Long productId, @PathVariable("count") Integer productCount){
        return Result.ok(productService.receive(productId,productCount));
    }

    @GetMapping("/skus/{id}/{count}")
    public Result skuStock(@PathVariable("id") Long productId, @PathVariable("count") Integer productCount){
        return Result.ok(productService.skuStock(productId,productCount));
    }

}
